package com.gollum.system.domain.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.gollum.jpa.domain.AbstractBaseEntity;
import com.gollum.jpa.domain.HertherBaseEnity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * 登录信息
 *
 * @author Herther
 * @version 1.0.0
 * @createTime 2022年09月03日 22:34:00
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain=true)
@Entity
@Table(name = "sys_logininfor")
public class SysLogininfor extends AbstractBaseEntity {

    private static final long serialVersionUID = 1L;


    /**  用户登录的账号 **/
    @Column(name = "username",length = 50)
    private String username;

    /** 登录来源 设备 **/
    @Column(name = "source_type")
    private String sourceType;

    /** 操作系统 **/
    @Column(name = "os",length = 100)
    private String os;

    /** 登录的ip地址 **/
    @Column(name = "ip_address",length = 100)
    private String ipAddress;

    /** 登录的地点 **/
    @Column(name = "ip_location")
    private String ipLocation;

    /** 返回的消息 **/
    @Column(name = "message")
    private String message;

    /** 登录的状态 0正常 1失败 **/
    @Column(name = "status",length = 10)
    private String status;

    /** 访问登录的时间 **/
    @DateTimeFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @Column(name = "login_time")
    private Date loginTime;


    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("ipAddress", getIpAddress())
                .append("username", getUsername())
                .append("sourceType", getSourceType())
                .append("os", getOs())
                .append("ipLocation", getIpLocation())
                .append("message", getMessage())
                .append("status", getStatus())
                .append("loginTime", getLoginTime())
                .toString();
    }

}
